package com.wxproject.demo.Controller.Word;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.wxproject.demo.Common.lang.ResultBody;
import com.wxproject.demo.Service.ImgAndWordVerify.TextCensor;
import com.wxproject.demo.Utils.UploadUtil;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author zqf
 * @date 2021/5/10 15:02
 * @description
 */
@RestController
public class WordVerifyTestController {

    @PostMapping("/uploadText/{context}")
    public ResultBody uploadText(@PathVariable("context")String context){
        String s = TextCensor.TextCensor(context);
        JsonParser jp = new JsonParser();
        JsonObject jo = jp.parse(s).getAsJsonObject();
        int conclusionType =jo.get("conclusionType").getAsInt();
        if (conclusionType!=1&&conclusionType!=3){
            String msg = jo.get("data").getAsJsonArray().get(0).getAsJsonObject().get("msg").getAsString();
            return ResultBody.error().message(msg);
        }
        return ResultBody.ok().message("发布成功");
    }

    @PostMapping("/uploadImgS")
    public ResultBody uploadImgS(@RequestParam("file") MultipartFile file) throws IOException {
        UploadUtil.uploadFileReturnUrlAndVerifyImg(file);
        return null;
    }
}
